package com.paw.distribute.session.resolver;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.session.web.http.HttpSessionIdResolver;

/**
 * @author lvzihai
 * @date 2021/6/18
 **/
@Slf4j
public class TokenHttpSessionIdResolver implements HttpSessionIdResolver {

  public static final String TOKEN = "token";

  public TokenHttpSessionIdResolver(){
  }

  @Override
  public List<String> resolveSessionIds (HttpServletRequest request) {
    List<String> list = new ArrayList<>();
    String token = request.getHeader(TOKEN);
    if(StrUtil.isNotEmpty(token)){
      list.add(token);
    }
    return list;
  }

  @Override
  public void setSessionId (HttpServletRequest request, HttpServletResponse response, String sessionId) {

  }

  @Override
  public void expireSession (HttpServletRequest request, HttpServletResponse response) {

  }

}
